package com.cjq.allservice.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cjq.allservice.entity.OrderDetail;
import com.cjq.allservice.entity.vo.OrderVo;
import com.cjq.allservice.service.OrderDetailService;
import com.cjq.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cjq
 * @since 2022-03-24
 */
@RestController
@RequestMapping("/allservice/order-detail")
@CrossOrigin
public class OrderDetailController {


    private final OrderDetailService orderDetailService;

    public OrderDetailController(OrderDetailService orderDetailService){
        this.orderDetailService=orderDetailService;
    }


    @ApiOperation("获取用户的所有订单详情")
    @GetMapping("/getAllOrdersDetail")
    public R getAllOrdersDetail(@RequestParam String orderId){
        QueryWrapper<OrderDetail> wrapper = new QueryWrapper<>();
        wrapper.eq("order_id",orderId);
        List<OrderDetail> list = orderDetailService.list(wrapper);
        return R.succ().data("orderDetailList",list).message("订单详情列表获取成功！！！");
    }

    @ApiOperation("获取所有订单详情")
    @GetMapping("/getDetails")
    public R getDetails(@RequestParam String orderId){
        List<OrderVo> orderVo = orderDetailService.getOrderVo(orderId);
        return R.succ().data("orders",orderVo);
    }

}

